package org.ch02.job.test08;

import java.lang.reflect.Field;

/**
 * @author XCH
 * @date 2025 - 03 - 18
 */
public class SqlGenerate {
    public static String generateSelect(Class<?> clz){
        // 获取表名
        String tableName = clz.getSimpleName();
        // 获取字段
        Field[] fields = clz.getDeclaredFields();
        // 拼接sql
        StringBuilder sql = new StringBuilder("select ");
        // 遍历字段
        for (Field field : fields){
            sql.append(field.getName()).append(",");
        }
        // 删除最后一个逗号
        if (sql.length() > 0){
            sql.deleteCharAt(sql.length() - 1);
        }
        sql.append(" from ").append(tableName);
        return  sql.toString() ;
    }
}
